package cn.wenlihelp.model;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.Optional;

@Data
@Accessors(chain = true)
public class Result <T>{
    private int code;
    private Long count;
    private String msg;
    private List<T> data;

    public static <T> Result<T> success(String msg,long count,List<T> data){
        return new Result<T>().setCode(0).setCount(count).setMsg(msg).setData(data);
    }
    public static <T> Result<T> success(long count,List<T> data){
        return new Result<T>().setCode(0).setMsg("成功").setCount(count).setData(data);
    }
    public static <T> Result<T> success(List<T> data){
        return success("成功", Optional.ofNullable(data).map(List::size).orElse(0),data);
    }

    public static <T> Result<T> failure(Integer code){
        return new Result<T>().setCode(code);
    }
}
